Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Optimise dockerfiles, fix ci, release images #444

Merged
merged 23 commits into from
Dec 1, 2023
Merged

Optimise dockerfiles, fix ci, release images #444

merged 23 commits into from
Dec 1, 2023

Conversation

spwoodcock
Copy link
Member

@spwoodcock spwoodcock commented Nov 8, 2023

Fixes #439

  • Updated to multi-stage builds.
  • Only installed required runtime libs for final underpass image.
  • Reordered layers for more efficient caching.
  • Added labels.

Significant image size reductions:

  • api 1.31GB --> 228MB
  • underpass 2.5GB --> 1.88GB
  • ui 1.1GB --> 18.5MB

The underpass image could probably be reduced further by selective usage of boost libraries, instead of libboost-all-dev.

Note

With the images being named ghcr.io/xxx/xxx it would be possible to push them to the underpass repo container registry.

Update 09/11/2023

  • Added stages to image:
    • debug for local testing.
    • ci for ci tests.
    • prod for production image.
  • Added workflow for publishing release images.
  • Set ci_local.sh to use the ci image, with bundled entrypoint.
  • Added github workflow local testing via act
  • Made ports user configurable via env vars.
  • Made image names configurable via env vars.
  • Note: ci_local uses docker compose V2 (docker compose instead of docker-compose)
    • It's the standard tool now bundled with docker install (a re-implementation in Go instead of Python, better in every way).

Copy link
Collaborator

@emi420 emi420 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build is working, but some things are failing or missing.

  • The directory /code changed, and with this, the bootstrap script stopped working for Docker
  • The API port changed, so the UI is not working now
  • The source files and the utils folder is missing, so the bootstrap script is not available anymore

Keep in mind that the Docker image is not only for deployment, but also for running Underpass locally. Maybe we can have two different Docker images, one for deployment and one for development/testing/running locally.

docker/underpass-ui.dockerfile Outdated Show resolved Hide resolved
docker/underpass.dockerfile Outdated Show resolved Hide resolved
docker-compose.yml Outdated Show resolved Hide resolved
docker/underpass.dockerfile Outdated Show resolved Hide resolved
@spwoodcock
Copy link
Member Author

The standard way to have different environments is to add different stages to the dockerfile.

I usually have a debug stage, and a prod stage. The target can be specified when you build (using docker compose, gh-workflows, etc).

@spwoodcock spwoodcock changed the title Optimise dockerfiles (multi stage, caching) Optimise dockerfiles, fix ci, release images Nov 9, 2023
@spwoodcock
Copy link
Member Author

Made updates: see in the first post.

Let me know if anything else needs updating 👍

@spwoodcock
Copy link
Member Author

Made the final update just now:

  • Create debug images for local debug stage and prod stage for the actual releases.
  • Bind mount local code into the containers so you get live updates for both fastapi and cosmos.

I can build and push the images to the hotosm container registry.
The only thing left to do @emi420 is to associate the packages with the repo (only the repo owner can do that):
https://github.com/orgs/hotosm/packages/container/package/underpass
https://github.com/orgs/hotosm/packages/container/package/underpass%2Fapi
https://github.com/orgs/hotosm/packages/container/package/underpass%2Fui
'Link this package to a repository'

@spwoodcock
Copy link
Member Author

I will rebase with master to solve conflicts.

Copy link
Collaborator

@emi420 emi420 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's mostly working! with docker-compose up -d the UI is not working but if I change the port is working perfectly:

ports:
- "${UI_PORT:-5000}:5000"

CI is failing, possibly because the workflow version and GitHub settings, you know better what changes are needed there.

Thanks @spwoodcock

docker-compose.yml Outdated Show resolved Hide resolved
@spwoodcock
Copy link
Member Author

Easiest to merge this to test my theory: the workflow is failing with image reg permissions as it was created before the GITHUB_TOKEN permissions were set correctly 👍

@spwoodcock spwoodcock merged commit 374eff9 into hotosm:master Dec 1, 2023
2 of 4 checks passed
@spwoodcock spwoodcock deleted the build/multi-stage-dockerfiles branch December 1, 2023 09:15
@spwoodcock
Copy link
Member Author

That seemed to work 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Optimise dockerfiles (multi-stage, caching)
2 participants